package linkedlist.leetcode;

/**
 * @author lynn
 * @date 18-12-15 下午1:54
 */
public class Sum {

    public static int sum(int[] array){
        return sum(array,0);
    }


    private static int sum(int[] array,int l){

        // 求解最基本问题
        if( l == array.length){
            return 0;
        }

        // 把原问题转化成更小的问题
        return array[l] + sum(array,l + 1);
    }

    public static void main(String[] args) {

        int[] nums = {1,2,3,4,5,6,7,8};
        System.out.println(sum(nums));

    }

}
